package me.firstapp.service.weixin.soft.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import me.firstapp.common.utils.Page;
import me.firstapp.common.utils.StrUtils;
import me.firstapp.module.weixin.member.SoftFee;
import me.firstapp.repository.weixin.member.SoftFeeRepository;
import me.firstapp.service.weixin.soft.SoftFeeService;

@Service
public class SoftFeeServiceImpl implements SoftFeeService {

	@Autowired
	private SoftFeeRepository softFeeRepository;

	@Override
	public List<SoftFee> findSoftFeeList() {
		return softFeeRepository.findSoftFeeList();
	}

	@Override
	public Page<SoftFee> findSoftFeePage(Integer pageNo, Integer pageSize, Map<String, Object> searchParams,
			String sortParam, String sortType) {
		return softFeeRepository.findSoftFeePage(pageNo, pageSize, searchParams, sortParam, sortType);
	}

	@Override
	public SoftFee executeAddSoftFee(Integer vipLevel, Integer validDays, BigDecimal price,
			BigDecimal chiefBaseVipJinBi, BigDecimal chiefHighVipJinBi, BigDecimal chiefBaseVipPoint,
			BigDecimal chiefHighVipPoint, String remark) {
		SoftFee softFee = new SoftFee();
		softFee.setVipLevel(vipLevel);
		softFee.setValidDays(validDays);
		softFee.setPrice(price);
		softFee.setChiefBaseVipJinBi(chiefBaseVipJinBi);
		softFee.setChiefHighVipJinBi(chiefHighVipJinBi);
		softFee.setChiefBaseVipPoint(chiefBaseVipPoint);
		softFee.setChiefHighVipPoint(chiefHighVipPoint);
		softFee.setRemark(remark);
		softFeeRepository.save(softFee);
		return softFee;
	}

	@Override
	public SoftFee executeUpdateSoftFee(Long id, Integer vipLevel, Integer validDays, BigDecimal price,
			BigDecimal chiefBaseVipJinBi, BigDecimal chiefHighVipJinBi, BigDecimal chiefBaseVipPoint,
			BigDecimal chiefHighVipPoint, String remark) {
		SoftFee softFee = (SoftFee) softFeeRepository.getById(id);
		if (null != vipLevel) {
			softFee.setVipLevel(vipLevel);
		}
		if (null != validDays) {
			softFee.setValidDays(validDays);
		}
		if (null != price) {
			softFee.setPrice(price);
		}
		if (null != chiefBaseVipJinBi) {
			softFee.setChiefBaseVipJinBi(chiefBaseVipJinBi);
		}
		if (null != chiefHighVipJinBi) {
			softFee.setChiefHighVipJinBi(chiefHighVipJinBi);
		}
		if (null != chiefBaseVipPoint) {
			softFee.setChiefBaseVipPoint(chiefBaseVipPoint);
		}
		if (null != chiefHighVipPoint) {
			softFee.setChiefHighVipPoint(chiefHighVipPoint);
		}
		if (StrUtils.isNotNULL(remark)) {
			softFee.setRemark(remark);
		}

		softFeeRepository.update(softFee);
		return softFee;
	}

	@Override
	public SoftFee findSoftFee(Long id) {
		return (SoftFee) softFeeRepository.getById(id);
	}

	@Override
	public SoftFee findSoftFeeByLevel(Integer vipLevel) {
		return softFeeRepository.findSoftFeeByLevel(vipLevel);
	}

}
